/**
 * 
 */
package org.jenkon.builder;

import java.io.Serializable;

import org.jenkon.validator.Validator;

/**
 * @author Jens Konopka
 * 
 */
public class ValidatorBuilder implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8206577148741170729L;

	private boolean valid = true;

	/** 
	 * @param validator {@link Validator} Implementation
	 * @param value The value object
	 * @return this current instance of {@link ValidatorBuilder}
	 * @see #append(Validator, Object, boolean)
	 */
	public <T> ValidatorBuilder append(final Validator<T> validator, final T value) {
		return append(validator, value, false);
	}

	/**
	 * @param validator {@link Validator} Implementation
	 * @param value The value object
	 * @param exclude expression to exclude the validation of value
	 * @return this current instance of {@link ValidatorBuilder}
	 */
	public <T> ValidatorBuilder append(final Validator<T> validator, final T value, final boolean exclude) {
		
		if (!exclude) {
			if (valid) {
				valid = validator.isValid(value);
			}
		}
		
		return this;
	}

	/**
	 * @return the valid
	 */
	public boolean isValid() {
		return valid;
	}

}
